package com.dhcc.bpm.modules.alarm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.alarm.entity.Template;
import com.dhcc.bpm.modules.alarm.service.ITemplateService;
import com.dhcc.bpm.modules.alarm.vo.TemplateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName TemplateController
 * @Description 告警内容模板表 控制器
 * @Author sjm
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@RestController
@AllArgsConstructor
@RequestMapping("bpm-alarm/template")
@Api(value = "告警内容模板表", tags = "告警内容模板表接口")
public class TemplateController extends BladeController {

	private ITemplateService templateService;

	/**
	 * @Description 详情
	 * @Author xiafayu
	 * @Date 2020/2/24 17:21
	 * @param template
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.alarm.entity.Template>
	 **/
	@ApiLog("告警内容详情")
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入template")
	@Log(title = "告警内容模板表",businessType = BusinessType.SELECT)
	public R<Template> detail(Template template) {
		Template detail = templateService.getOne(Condition.getQueryWrapper(template));
		return R.data(detail);
	}

	/**
	 * @Description 分页 告警内容模板表
	 * @Author xiafayu
	 * @Date 2020/2/24 17:21
	 * @param template
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.alarm.entity.Template>>
	 **/
	@ApiLog("告警内容分页")
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入template")
	@Log(title = "告警内容模板表分页",businessType = BusinessType.SELECT)
	public R<IPage<Template>> list(Template template, Query query) {
		IPage<Template> pages = templateService.page(Condition.getPage(query), Condition.getQueryWrapper(template));
		return R.data(pages);
	}

	/**
	 * @Description 自定义分页 告警内容模板表
	 * @Author xiafayu
	 * @Date 2020/2/24 17:21
	 * @param template
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.alarm.vo.TemplateVO>>
	 **/
	@ApiLog("告警内容分页")
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入template")
	@Log(title = "告警内容模板表分页",businessType = BusinessType.SELECT)
	public R<IPage<TemplateVO>> page(TemplateVO template, Query query) {
		IPage<TemplateVO> pages = templateService.selectTemplatePage(Condition.getPage(query), template);
		return R.data(pages);
	}

	/**
	 * @Description 新增 告警内容模板表
	 * @Author xiafayu
	 * @Date 2020/2/24 17:22
	 * @param template
	 * @return org.springblade.core.tool.api.R
	 **/
	@ApiLog("告警内容新增")
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入template")
	@Log(title = "告警内容模板表新增",businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody Template template) {
		return R.status(templateService.save(template));
	}

	/**
	 * @Description 修改 告警内容模板表
	 * @Author xiafayu
	 * @Date 2020/2/24 17:22
	 * @param template
	 * @return org.springblade.core.tool.api.R
	 **/
	@ApiLog("告警内容修改")
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入template")
	@Log(title = "告警内容模板表新增",businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody Template template) {
		return R.status(templateService.updateById(template));
	}

	/**
	 * @Description 新增或修改 告警内容模板表
	 * @Author xiafayu
	 * @Date 2020/2/24 17:22
	 * @param template
	 * @return org.springblade.core.tool.api.R
	 **/
	@ApiLog("告警内容新增修改")
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入template")
	@Log(title = "告警内容模板表新增",businessType = BusinessType.UPDATE)
	public R submit(@Valid @RequestBody Template template) {
		return R.status(templateService.saveOrUpdate(template));
	}

	
	/**
	 * @Description 删除 告警内容模板表
	 * @Author xiafayu
	 * @Date 2020/2/24 17:22
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@ApiLog("告警内容删除")
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	@Log(title = "告警内容模板表删除",businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(templateService.removeByIds(Func.toLongList(ids)));
	}

	
}
